package com.peanut.baby.mvp.mycontent;

import android.app.Activity;

import com.peanut.baby.InitManager;
import com.peanut.baby.http.BaseObserver;
import com.peanut.baby.http.BaseScheduler;
import com.peanut.baby.http.RetrofitClient;
import com.peanut.baby.model.PTag;
import com.peanut.baby.model.User;

import java.util.List;

import cn.nekocode.rxlifecycle.RxLifecycle;
import io.reactivex.Observable;

/**
 * Created by anonymouslystudio on 2017/8/22.
 */

public class MyPresenter implements MyContract.Presenter {

    private MyContract.View view;
    Activity activity;

    public MyPresenter(MyContract.View view, Activity activity) {
        this.view = view;
        this.activity = activity;
    }

    @Override
    public void getUserInfo(String userId) {
        Observable obs = RetrofitClient.getInstance().getFamousInfo(userId, InitManager.getInstance().getUserId());
        obs.compose(BaseScheduler.<User>compose()).compose(RxLifecycle.bind(activity).withObservable())
                .subscribe(new BaseObserver<User>() {
                    @Override
                    protected void onHandleSuccess(User o) {
                        view.onGetUserInfo(o);
                    }

                    @Override
                    protected void onHandleError(String code, String msg) {
                        view.onGetUserInfoFailed(msg);
                    }
                });
    }
}
